// 新消息提醒
var titleInit = document.title,
    isShine = true;

window.onfocus = function () {
    isShine = false;
};
window.onblur = function () {
    isShine = true;
};

// for IE
document.onfocusin = function () {
    isShine = false;
};
document.onfocusout = function () {
    isShine = true;
};

// 待办列表
var thingsGridColumns1 = [{
    id: 'title',
    title: '标题',
    type: 'string',
    columnClass: 'text-center',
},
    {
        id: 'sqNr',
        title: '主要内容',
        type: 'string',
        width: 200,
        columnClass: 'text-center',
    },
    {
        id: 'lcInitiatorName',
        title: '发起人',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
    },
    {
        id: 'createTime',
        title: '提交时间',
        type: 'date',
        width: 120,
        format: 'MM/dd hh:mm:ss',
        otype: 'time_stamp_ms'
    },
    {
        id: 'operation',
        title: '操作',
        width: 70,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            content += '<button class="btn btn-xs btn-success" onclick="toDo(\'' + record.id + '\');"' + '><i class="fa fa-edit"></i>  待办</button>';
            return content;
        }
    }
];
// 待办类型跳转
function toDo(scheduleId) {
    ;
    window.location.href = "#/router/" + scheduleId;
}

function getProMgId() {

}

function getProDt($scope, CertusFormAjax, CertusJsonAjax) {
    this.ref = function () {
        //项目动态
        CertusFormAjax.ajax("findProDynamics", {}, function (response) {
            $scope.dt = response.data;
        });
        //通知消息
        CertusFormAjax.ajax("findPersonNotices", {}, function (response) {
            $scope.zt = response.data;
        });

        CertusFormAjax.ajax("findNoticeTop5", {}, function (response) {
            $scope.sysinfo = response.data.list;
        });
        //工作安排
        CertusFormAjax.ajax("findCompPlans", {}, function (response) {
            var arr = [];
            var data = response.data;
            for (var i = 0; i < data.length; i++) {
                if (i < 5) {
                    arr.push(data[i]);
                }
            }
            $scope.complans = arr;
            var planList = data;
            // console.log(planList)
            var content = '';
            for (var i = 0; i < planList.length; i++) {

                var date = new Date(planList[i].createTime);
                Y = date.getFullYear() + '-';
                M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                D = date.getDate() + ' ';
                h = date.getHours() + ':';
                m = date.getMinutes() + ':';
                s = date.getSeconds();
                var time = Y + M + D + h + m + s;

                content +=
                    '<div class="msg-time-chat" >' +
                    '<div class="message-body msg-in">' +
                    '<span class="arrow"></span>' +
                    '<div class="text">' +
                    '<p class="attribution">' +
                    '<a href="javascript:void(0);">' +
                    '<i class="icon-bullhorn icon-r5"></i>' + time +
                    '</a>' +
                    '</p> ' +
                    '<p>' + planList[i].content + '</p>' +
                    '</div>' +
                    '</div>' +
                    '</div>'
            }
            $("#planList").append(content);
        });
    };
    ref();
    // setInterval(function () {ref()  },30000);
}


//查询待办信息
function findList(CertusJsonAjax) {
    this.ref2 = function () {
        $("#thingsDataGird1").empty();
        // CertusJsonAjax.dataInit("findSdu2", {}, thingsGridColumns1, "thingsDataGird1", 7);
        CertusJsonAjax.ajaxNode("tschedule","list5new",{userId:"901111"},function(data){
            CertusJsonAjax.initDataGrid(thingsGridColumns1,"thingsDataGird1",null,data)
        })

    }
    ref2();
    // setInterval(function () {
    //     ref2()
    // }, 30000);
}

function search($scope, CertusFormAjax, CertusJsonAjax) {


    // 找人查询
    var userGridColumns = [{
        id: 'userName',
        title: '姓名',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
    },
        {
            id: 'render',
            title: '性别',
            type: 'string',
            width: 50,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '';
                if (record.sex == 1) {
                    content += '男';
                } else {
                    content += '女';
                }
                return content;
            }
        },
        {
            id: 'leaderName',
            title: '直接领导',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        },
        {
            id: 'departmentName',
            title: '部门',
            type: 'string',
            width: 200,
            columnClass: 'text-center'
        },
        {
            id: 'positonName',
            title: '岗位',
            type: 'string',
            width: 200,
            columnClass: 'text-center',
        },
        {
            id: 'phoneNumber',
            title: '联系方式',
            type: 'string',
            width: 110,
            columnClass: 'text-center',
        },
        {
            id: 'email',
            title: '邮箱地址',
            type: 'string',
            columnClass: 'text-left',
        },
        {
            id: 'userId',
            title: '工号',
            type: 'string',
            columnClass: 'text-left',
        },
        {
            id: 'belongCompanyCode',
            title: '所属公司',
            type: 'string',
            width: 120,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '';
                if (record.belongCompanyCode == 'STSJT') {
                    return "赛特斯集团";
                } else if (record.belongCompanyCode == 'STSNJ') {
                    return "赛特斯南京"
                } else if (record.belongCompanyCode == 'STSBJ') {
                    return "赛特斯北京"
                } else if (record.belongCompanyCode == 'STSGD') {
                    return "赛特斯广州"
                } else if (record.belongCompanyCode == 'STSSH') {
                    return "赛特斯上海"
                } else if (record.belongCompanyCode == 'HFKJ') {
                    return "浩方科技"
                } else if (record.belongCompanyCode == 'HFXX') {
                    return "浩方信息"
                } else if (record.belongCompanyCode == 'SYB-RX') {
                    return "融合运维事业部"
                }
            }
        }
    ];

    $("#searchUser").on("click", function () {
        $("#userDataGird").empty();
        $("#userGridToolBarContainer").empty();
        CertusJsonAjax.dataInit("searchCompany", {
            "param": $("#searchInputId").val()
        }, userGridColumns, 'userDataGird', 'userGridToolBarContainer')
    });
}